(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.city.deleteRejectController', deleteRejectController);
	deleteRejectController.$inject = [ '$scope', 'Constants', 'modalService', 'gridService', 'layoutConfig', 'validatorConfig', 'authService',
			'cityService' ];
	function deleteRejectController($scope, Constants, modalService, gridService, layoutConfig, validatorConfig, authService, cityService) {
		var ctrl = this, params = $scope.$stateParams.params, errorMessage = {};
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		
		ctrl.init = function() {
			authService.deleteReject(params).then(function(response) {
				if (response.data && response.data.model && response.data.task) {
					ctrl.city = response.data.model;
					ctrl.city.taskId = response.data.task.taskId;
				}
			});
		};

		ctrl.deleteRejectSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.city.primaryKey]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteRejectSubmit(ctrl.city).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};
		
		ctrl.deleteRejectCancel = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.cancel', args : [ctrl.city.primaryKey]} ],
				'btnCallback' : {
					'ok' : function() {
						authService.deleteRejectCancel(ctrl.city).then(cancelSuccessful, cancelFailed);
					}
				}
			});
		};
		

		function rowSelectionChanged(eventRow, selectedRows) {
			ctrl.selectedSubCommpanyList = selectedRows;
		}

		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.city.list',
					'state' : 'cda.city.list',
					'params' : {}
				}]
			});
		}

		function submitFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}

		function cancelSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.cancel' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.city.list',
					'state' : 'cda.city.list',
					'params' : {}
				}]
			});
		}
		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		function cancelFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}		
	}
})(angular);